<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="js/jquery/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="js/jquery/jquery.easyui.min.js"></script>
    <link id="easyuiTheme" rel="stylesheet" href="css/easyui.css" type="text/css"></link>
    <link rel="stylesheet"  href="css/icon.css" type="text/css"></link>
     <script type="text/javascript" src="js/jquery/easyui-lang-zh_CN.js"></script>
       <!--自定义验证-->
    <script src="js/jquery/validator.js" type="text/javascript"></script>
     <script type="text/javascript" src="js/jquery/jquery.datagrid.js"></script>
    
<script type="text/javascript">
            
            $(function(){
                $('input[type=text]').validatebox();
                
                $('#listTable').datagrid({
                url:'daytaskFinish/list',
                loadMsg:'数据加载中........',
                toolbar: [{
                text:'增加',
                iconCls: 'icon-add',
                handler: function(){addRole()}
            },'-',{
                text:'删除',
                iconCls: 'icon-remove',
                handler: function(){deleteRecords( $('#listTable').datagrid('getSelections')) }
            },'-',{
                text:'修改',
                iconCls: 'icon-edit',
                handler: function(){          	 
                	 edit() 	}
            },'-',{
                text:'维护',
                iconCls: 'icon-cut',
                handler: function(){}
            },'-',{
                text:'分配',
                iconCls: 'icon-edit',
                handler: function(){}
            }], 
               //idField:'uuid',//不同页面保持选择状态
                striped:true,
                border:true,
                fit:true,
                rownumbers:true,
                pagination:true,
                fitColumns:true,
              //  hideColumn:'caption',

                pageSize:20,
                pageList:[20,30,40,50],
                  columns:[[
                  {field:'uuid',checkbox:true},
                  {field:'sontasktypename',title:'任务名称',width:50,align:'center'},
				  {field:'finishnum',title:'完成数量',width:50,align:'center'},
                  {field:'finishday',title:'完成时间',width:50,align:'center'},
                //  {field:'caption',title:'',width:0,align:'center'},    

                        ]]
                })
                //.datagrid('hideColumn', 'caption');   如果需要隐藏某一列
                        })
                        
        /**
        *增加角色
        */                
                        function addRole(){
                        
                        $('#dialog').dialog({  
                                title: '添加任务',  
                                width: 280,  
                                height: 230,  
                                cache: false,  
                                modal: true,
                                closable:false,//不显示关闭按钮
                                buttons: [
                                {
                                text:'提交',
                                iconCls:'icon-ok',
                                handler:function(){
                                	//var selectText=$("#tasktypeid").combobox("getValue");
                                	//alert(selectText);
                                var finishnum=$('#finishnum').val();
                                if(finishnum>0){
                                        $('#addROLEFORM').form('submit',{   
                                            url:'daytaskFinish/add',   
                                            onSubmit: function(){
                                                 return $(this).form('validate');
                                            },   
                                            success:function(data){       
                                                var result=$.parseJSON(data);
                                                if(result.status==0){
                                             	   $.messager.alert(result.title, result.message,result.msgLeavl);
                                                }else{
                                              	   $.messager.alert(result.title, result.message,result.msgLeavl);
                                                    $('#listTable').datagrid('load');
                                                    $('#dialog').dialog('close');

                                                }    
                                              }   
                                        })      
                                }
                                                                                    
                            }},{
                            text:'取消',handler:function(){
                            $('#dialog').dialog('close');
                            }}
                            ]  
                            
                            }) 
                        
                        } 
            
            function edit(){
               var rows = $('#listTable').datagrid('getSelections');
               if (rows.length==1){
               $("#id").val(rows[0].id); 
              // $("#tasktypeid").attr("text",rows[0].tasktypeid) ; 
               $("#sontasktypeid").combobox("setValue",rows[0].sontasktypeid) ; 
               $("#finishnum").val(rows[0].finishnum); 
               $("#finishday").datetimebox("setValue",rows[0].finishday); 
               
            	 $('#dialog').dialog({  
                     title: '修改数据',  
                     width: 280,  
                     height: 230,  
                     cache: false,  
                     modal: true,
                     closable:false,//不显示关闭按钮
                     buttons: [
                     {
                     text:'提交',
                     iconCls:'icon-ok',
                     handler:function(){
               
                     var finishnum=$('#finishnum').val();
                     if(finishnum>0){
                             $('#addROLEFORM').form('submit',{   
                                 url:'daytaskFinish/edit',   
                                 onSubmit: function(){
                                      return $(this).form('validate');
                                 },   
                                 success:function(data){       
                                     var result=$.parseJSON(data);
                                     if(result.status==0){
                                  	   $.messager.alert(result.title, result.message,result.msgLeavl);
                                     }else{
                                   	   $.messager.alert(result.title, result.message,result.msgLeavl);
                                         $('#listTable').datagrid('load');
                                         $('#dialog').dialog('close');

                                     }    
                                   }   
                             })      
                     }
                                                                         
                 }},{
                 text:'取消',handler:function(){
                 $('#dialog').dialog('close');
                 }}
                 ]  
                 
                 }) 
               }else{
            	   $.messager.alert("系统提示","对不起，该操作 必须选择一行！",'error'); 
            	   return; 
               }
                

            	
              
            }
            
            //批量删除
            function deleteRecords(rows){
            	if (!rows || rows.length <= 0) {
            		$.messager.alert('提示', '请选择要删除的数据!', 'info');
            		return;
            		}
            	else if(rows.length  >=1 ) {//选中几行的话触发事件
            		 $.messager.confirm('Confirm','确定删除?', function (res) {//提示是否删除
            		if (res) {
           			var codes=new Array();
           			$.each(rows, function (i, n) {
            		 codes.push(rows[i].id);
           			});
            		codes.join(',')
            		deleteRecord(codes.toString());//拼接字符串并传递到后台处理数据，循环删除，成功后刷新datagrid
            		}
            		});
            		}
            }
            
            function deleteRecord(deleteIds) {
                   $.post('daytaskFinish/delete',{deleteIds:deleteIds},function(result){
                	   $.messager.alert(result.title, result.message,result.msgLeavl);
                	   $('#listTable').datagrid('reload');    // reload the user data
                               },'json');
                           }
                  
            
            
        </script>
    </head>
    <body>
  
	
    <!-- 查询 -->
            <table id="listTable"></table>
    <!-- 弹出对话框增加form -->
    <div id="dialog">
        <form id="addROLEFORM" method="post">  
        <input type="hidden" id="id" name="daytaskFinish.id"  />
            <table align="center">
             <tr align="right">            
                    <tr>
                    <td>任务类别:</td>
                    <td>
                    <input class="easyui-combobox"  name="daytaskFinish.sontasktypeid" 	id="sontasktypeid"
							url="sontasktype/selection" 
							valueField="id" 
							textField="name" 
							panelHeight="auto"   editable="false" /></td>
                </tr>
                
                <tr align="right">            
                    <tr>
                    <td>完成数量:<font color='red'>*</font></td>
                    <td><input class="easyui-validatebox" id="finishnum"  name="daytaskFinish.finishnum" data-options="required:true,validType:'intOrFloat',missingMessage:'请输入合法的数字',tipPosition:'right'" ></input></td>
                </tr>
             
                
                <tr align="right">            
                    <tr>
                    <td>完成时间:</td>
                    <td><input class="easyui-datetimebox" id="finishday" name="daytaskFinish.finishday" data-options="required:true,missingMessage:'该输入项不能为空',tipPosition:'right'" ></input></td>
                </tr>
                
                 
           </table>
        </form>
    </div>
    
    
    </body>
    
    
</html>